﻿<template>
  <div>
    <a-card :bordered="false" :bodyStyle="tstyle">

      <div class="table-page-search-wrapper" v-if="hasPerm('SysDepartment:page')">
        <a-form layout="inline">
          <a-row :gutter="48">
            <a-col :md="8" :sm="24">
              <a-form-item label="DEPT_CODE ">
                <a-input v-model="queryParam.deptCode" allow-clear placeholder="请输入DEPT_CODE "/>
              </a-form-item>
            </a-col>
            <a-col :md="8" :sm="24">
              <a-form-item label="DEPT_NAME ">
                <a-input v-model="queryParam.deptName" allow-clear placeholder="请输入DEPT_NAME "/>
              </a-form-item>
            </a-col><template v-if="advanced">
              <a-col :md="8" :sm="24">
                <a-form-item label="DEPT_ATTR1 ">
                  <a-input v-model="queryParam.deptAttr1" allow-clear placeholder="请输入DEPT_ATTR1 "/>
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="DEPT_ATTR2 ">
                  <a-input v-model="queryParam.deptAttr2" allow-clear placeholder="请输入DEPT_ATTR2 "/>
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="INPUT_CODE ">
                  <a-input v-model="queryParam.inputCode" allow-clear placeholder="请输入INPUT_CODE "/>
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="INPUT_CODE_WB ">
                  <a-input v-model="queryParam.inputCodeWb" allow-clear placeholder="请输入INPUT_CODE_WB "/>
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="DEPT_ADDR ">
                  <a-input v-model="queryParam.deptAddr" allow-clear placeholder="请输入DEPT_ADDR "/>
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="SICKBEDS ">
                  <a-input v-model="queryParam.sickbeds" allow-clear placeholder="请输入SICKBEDS "/>
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="REMARK1 ">
                  <a-input v-model="queryParam.remark1" allow-clear placeholder="请输入REMARK1 "/>
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="REMARK2 ">
                  <a-input v-model="queryParam.remark2" allow-clear placeholder="请输入REMARK2 "/>
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="REMARK3 ">
                  <a-input v-model="queryParam.remark3" allow-clear placeholder="请输入REMARK3 "/>
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="REMARK4 ">
                  <a-input v-model="queryParam.remark4" allow-clear placeholder="请输入REMARK4 "/>
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="REMARK5 ">
                  <a-input v-model="queryParam.remark5" allow-clear placeholder="请输入REMARK5 "/>
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="REMARK6 ">
                  <a-input v-model="queryParam.remark6" allow-clear placeholder="请输入REMARK6 "/>
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="REMARK7 ">
                  <a-input v-model="queryParam.remark7" allow-clear placeholder="请输入REMARK7 "/>
                </a-form-item>
              </a-col><a-col :md="8" :sm="24">
                <a-form-item label="创建时间">
                  <a-date-picker style="width: 100%" placeholder="请选择创建时间" v-model="queryParam.createDateDate" @change="onChangecreateDate"/>
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="创建者Id">
                  <a-input v-model="queryParam.createUserId" allow-clear placeholder="请输入创建者Id"/>
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="创建者名称">
                  <a-input v-model="queryParam.createUserName" allow-clear placeholder="请输入创建者名称"/>
                </a-form-item>
              </a-col><a-col :md="8" :sm="24">
                <a-form-item label="更新时间">
                  <a-date-picker style="width: 100%" placeholder="请选择更新时间" v-model="queryParam.modifyDateDate" @change="onChangemodifyDate"/>
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="修改者Id">
                  <a-input v-model="queryParam.modifyUserId" allow-clear placeholder="请输入修改者Id"/>
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="修改者名称">
                  <a-input v-model="queryParam.modifyUserName" allow-clear placeholder="请输入修改者名称"/>
                </a-form-item>
              </a-col><a-col :md="8" :sm="24">
                <a-form-item label="删除时间">
                  <a-date-picker style="width: 100%" placeholder="请选择删除时间" v-model="queryParam.deleteDateDate" @change="onChangedeleteDate"/>
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="删除者ID">
                  <a-input v-model="queryParam.deleteUserId" allow-clear placeholder="请输入删除者ID"/>
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="删除者姓名">
                  <a-input v-model="queryParam.deleteUserName" allow-clear placeholder="请输入删除者姓名"/>
                </a-form-item>
              </a-col>            </template>

            <a-col :md="8" :sm="24" >
              <span class="table-page-search-submitButtons">
                <a-button type="primary" @click="$refs.table.refresh(true)" >查询</a-button>
                <a-button style="margin-left: 8px" @click="() => queryParam = {}">重置</a-button>
                <a @click="toggleAdvanced" style="margin-left: 8px"> {{ advanced ? '收起' : '展开' }}
                  <a-icon :type="advanced ? 'up' : 'down'"/>
                </a>
              </span>
            </a-col>

          </a-row>
        </a-form>
      </div>
    </a-card>
    <a-card :bordered="false">
      <s-table
        ref="table"
        :columns="columns"
        :data="loadData"
        :alert="true"
        :rowKey="(record) => record.iD"
        :rowSelection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }">
        <template class="table-operator" slot="operator" v-if="hasPerm('SysDepartment:add')" >
          <a-button type="primary" v-if="hasPerm('SysDepartment:add')" icon="plus" @click="$refs.addForm.add()">新增科室信息</a-button>
        </template>
        <span slot="action" slot-scope="text, record">
          <a v-if="hasPerm('SysDepartment:edit')" @click="$refs.editForm.edit(record)">编辑</a>
          <a-divider type="vertical" v-if="hasPerm('SysDepartment:edit') & hasPerm('SysDepartment:delete')"/>
          <a-popconfirm v-if="hasPerm('SysDepartment:delete')" placement="topRight" title="确认删除？" @confirm="() => SysDepartmentDelete(record)">
            <a>删除</a>
          </a-popconfirm>
        </span>
      </s-table>
      <add-form ref="addForm" @ok="handleOk" />
      <edit-form ref="editForm" @ok="handleOk" />
    </a-card>
  </div>
</template>
<script>
  import { STable } from '@/components'
  import moment from 'moment'
  import { SysDepartmentPage, SysDepartmentDelete } from '@/api/modular/main/SysDepartmentManage'
  import addForm from './addForm.vue'
  import editForm from './editForm.vue'
  export default {
    components: {
      STable,
      addForm,
      editForm
    },
    data () {
      return {
        advanced: false, // 高级搜索 展开/关闭
        queryParam: {},
        columns: [
          {
            title: 'DEPT_CODE ',
            align: 'center',
            dataIndex: 'deptCode'
          },
          {
            title: 'DEPT_NAME ',
            align: 'center',
            dataIndex: 'deptName'
          },
          {
            title: 'DEPT_ATTR1 ',
            align: 'center',
            dataIndex: 'deptAttr1'
          },
          {
            title: 'DEPT_ATTR2 ',
            align: 'center',
            dataIndex: 'deptAttr2'
          },
          {
            title: 'INPUT_CODE ',
            align: 'center',
            dataIndex: 'inputCode'
          },
          {
            title: 'INPUT_CODE_WB ',
            align: 'center',
            dataIndex: 'inputCodeWb'
          },
          {
            title: 'DEPT_ADDR ',
            align: 'center',
            dataIndex: 'deptAddr'
          },
          {
            title: 'SICKBEDS ',
            align: 'center',
            dataIndex: 'sickbeds'
          },
          {
            title: 'REMARK1 ',
            align: 'center',
            dataIndex: 'remark1'
          },
          {
            title: 'REMARK2 ',
            align: 'center',
            dataIndex: 'remark2'
          },
          {
            title: 'REMARK3 ',
            align: 'center',
            dataIndex: 'remark3'
          },
          {
            title: 'REMARK4 ',
            align: 'center',
            dataIndex: 'remark4'
          },
          {
            title: 'REMARK5 ',
            align: 'center',
            dataIndex: 'remark5'
          },
          {
            title: 'REMARK6 ',
            align: 'center',
            dataIndex: 'remark6'
          },
          {
            title: 'REMARK7 ',
            align: 'center',
            dataIndex: 'remark7'
          },
          {
            title: '创建时间',
            align: 'center',
            dataIndex: 'createDate'
          },
          {
            title: '创建者Id',
            align: 'center',
            dataIndex: 'createUserId'
          },
          {
            title: '创建者名称',
            align: 'center',
            dataIndex: 'createUserName'
          },
          {
            title: '更新时间',
            align: 'center',
            dataIndex: 'modifyDate'
          },
          {
            title: '修改者Id',
            align: 'center',
            dataIndex: 'modifyUserId'
          },
          {
            title: '修改者名称',
            align: 'center',
            dataIndex: 'modifyUserName'
          },
          {
            title: '删除时间',
            align: 'center',
            dataIndex: 'deleteDate'
          },
          {
            title: '删除者ID',
            align: 'center',
            dataIndex: 'deleteUserId'
          },
          {
            title: '删除者姓名',
            align: 'center',
            dataIndex: 'deleteUserName'
          }
        ],
        tstyle: { 'padding-bottom': '0px', 'margin-bottom': '10px' },
        // 加载数据方法 必须为 Promise 对象
        loadData: parameter => {
          return SysDepartmentPage(Object.assign(parameter, this.switchingDate())).then((res) => {
            return res.data
          })
        },
        selectedRowKeys: [],
        selectedRows: []
      }
    },
    created () {
      if (this.hasPerm('SysDepartment:edit') || this.hasPerm('SysDepartment:delete')) {
        this.columns.push({
          title: '操作',
          width: '150px',
          dataIndex: 'action',
          scopedSlots: { customRender: 'action' }
        })
      }
    },
    methods: {
      moment,
      /**
       * 查询参数组装
       */
      switchingDate () {
        const queryParamcreateDate = this.queryParam.createDateDate
        if (queryParamcreateDate != null) {
            this.queryParam.createDate = moment(queryParamcreateDate).format('YYYY-MM-DD')
            if (queryParamcreateDate.length < 1) {
                delete this.queryParam.createDate
            }
        }
        const queryParammodifyDate = this.queryParam.modifyDateDate
        if (queryParammodifyDate != null) {
            this.queryParam.modifyDate = moment(queryParammodifyDate).format('YYYY-MM-DD')
            if (queryParammodifyDate.length < 1) {
                delete this.queryParam.modifyDate
            }
        }
        const queryParamdeleteDate = this.queryParam.deleteDateDate
        if (queryParamdeleteDate != null) {
            this.queryParam.deleteDate = moment(queryParamdeleteDate).format('YYYY-MM-DD')
            if (queryParamdeleteDate.length < 1) {
                delete this.queryParam.deleteDate
            }
        }
        const obj = JSON.parse(JSON.stringify(this.queryParam))
        return obj
      },
      SysDepartmentDelete (record) {
        SysDepartmentDelete(record).then((res) => {
          if (res.success) {
            this.$message.success('删除成功')
            this.$refs.table.refresh()
          } else {
            this.$message.error('删除失败') // + res.message
          }
        })
      },
      toggleAdvanced () {
        this.advanced = !this.advanced
      },
      onChangecreateDate(date, dateString) {
        this.createDateDateString = dateString
      },
      onChangemodifyDate(date, dateString) {
        this.modifyDateDateString = dateString
      },
      onChangedeleteDate(date, dateString) {
        this.deleteDateDateString = dateString
      },
      handleOk () {
        this.$refs.table.refresh()
      },
      onSelectChange (selectedRowKeys, selectedRows) {
        this.selectedRowKeys = selectedRowKeys
        this.selectedRows = selectedRows
      }
    }
  }
</script>
<style lang="less">
  .table-operator {
    margin-bottom: 18px;
  }
  button {
    margin-right: 8px;
  }
</style>
